/***************************************************************************
*   Copyright (C) 2011 by Chuck Gao & Alex Liu                             *
*                                                                          *
*   This program is free software: you can redistribute it and/or modify   *
*   it under the terms of the GNU General Public License as published by   *
*   the Free Software Foundation, either version 3 of the License, or      *
*   (at your option) any later version.                                    *
*                                                                          *
*   This program is distributed in the hope that it will be useful,        *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
*   GNU General Public License for more details.                           *
*                                                                          *
*   You should have received a copy of the GNU General Public License      *
*   along with this program.  If not, see <http://www.gnu.org/licenses/>.  *
*                                                                          *
*   Contact author: chuckgao.cg@gmail.com                                  *
*                   alex2202375@gmail.com                                  *
***************************************************************************/

#include <QtGui/QApplication>
#include <QTextCodec>
#include <QDeclarativeContext>
#include <QDeclarativeEngine>
#include <qdeclarative.h>
//#include <QtOpenGL>
#include "cengine.h"
#include "qmlapplicationviewer.h"

using namespace cooking;

int main(int argc, char *argv[])
{
//#ifdef OPENGL_GRAPHICSSYSTEM
//    QApplication::setGraphicsSystem("opengl");
//#endif

    QApplication app(argc, argv);

    QTextCodec *codec = QTextCodec::codecForName("UTF-8");
    QTextCodec::setCodecForLocale(codec);
    QTextCodec::setCodecForCStrings(codec);
    QTextCodec::setCodecForTr(codec);

    QmlApplicationViewer viewer;
//    #ifndef OPENGL_GRAPHICSSYSTEM
//        QGLFormat format = QGLFormat::defaultFormat();
//        format.setSampleBuffers(false);
//        format.setSwapInterval(1);
//        QGLWidget* glWidget = new QGLWidget(format);
//        glWidget->setAutoFillBackground(false);
//        viewer.setViewport(glWidget);
//    #endif

    CEngine* engine = new CEngine;
    viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
    viewer.setAttribute(Qt::WA_OpaquePaintEvent);
    viewer.setAttribute(Qt::WA_NoSystemBackground);
    viewer.setMainQmlFile("QML/Cooking/main.qml");
    viewer.rootContext()->setContextProperty("engine", engine);
    viewer.showExpanded();

    return app.exec();
}
